from pymongo import MongoClient, DESCENDING, ASCENDING
import re
import platform
print('python v', platform.python_version())

# 连接数据库
client = MongoClient('mongodb://localhost:27017')
database = client['stocks']

names = database.collection_names()
# stock_collections = [x for x in names if re.match(r'^stock_', x)]
stock_collections = filter(lambda n: re.match(r'^stock_', n), names)

if input('confirm? (yes|no)') == 'yes':
    for collection in stock_collections:
        database.drop_collection(collection)
        print('删除', collection)

    print('成功删除', len(list(stock_collections)))
else:
    print('取消操作')
